const glob = require('glob')
const path = require('path')

const pageEntryName = 'app'
const pages = glob.sync(`./src/pages/**/${pageEntryName}.js`).reduce((pages, path) => {
  const chunk = path.split('./src/pages/')[1].split(`/${pageEntryName}.js`)[0]
  pages[chunk] = {
    entry: `src/pages/${chunk}/${pageEntryName}.js`,
    template: path.replace(/.js/g, '.html'),
    filename: `${chunk}.html`,
  }
  return pages
}, {})

// console.log('pages', pages)

function resolve (dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  pages,
  lintOnSave: false,
  publicPath: process.env.NODE_ENV === 'production' ? '':'',
  productionSourceMap: false,
  assetsDir: 'assets',
  chainWebpack: (config) => {
    config.resolve.alias
      .set('@$', resolve('src'))
      .set('src', resolve('src'))
      .set('assets', resolve('src/assets'))
      .set('components', resolve('src/components'))
      .set('layout', resolve('src/layout'))
      .set('base', resolve('src/base'))
  },

  css: {
    loaderOptions: {
      sass: {
        data: `@import "@/style/_value.scss";`
      }
    }
  },

  devServer: {
    open: false,
    host: '0.0.0.0',
    port: 8010,
    https: false,
    hotOnly: false,
    historyApiFallback: false,
    noInfo: true,
    proxy: {
      '/online/*': {
        pathRewrite: {
          '/online': '',
        },
        // target: 'http://data.seibanet.cn/',
        // target: 'http://testnft.dappx.store/',
        target: 'http://heroapi.juhuixinkj.com/api/threeKingdom/',
        // target: 'http://heroapi.juhuixinkj.com/api/testthreeKingdom/',
        changeOrigin: true
      }
    },
  },

  pluginOptions: {
  }
}
